"""
状态管理器
"""
import json
from typing import Dict, Any
from datetime import datetime

class StatusManager:
    """状态管理器"""
    
    def __init__(self):
        self.status_history = {}
    
    def update_status(self, task_id: str, status_data: Dict[str, Any]):
        """更新状态"""
        if task_id not in self.status_history:
            self.status_history[task_id] = []
        
        status_data['timestamp'] = datetime.now().isoformat()
        self.status_history[task_id].append(status_data)
    
    def get_status_history(self, task_id: str) -> list:
        """获取状态历史"""
        return self.status_history.get(task_id, [])
    
    def export_status(self, task_id: str, filepath: str):
        """导出状态到文件"""
        history = self.get_status_history(task_id)
        with open(filepath, 'w', encoding='utf-8') as f:
            json.dump(history, f, ensure_ascii=False, indent=2)